package cn.itheima.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(value = "/ServletTest1" ,dispatcherTypes = {DispatcherType.REQUEST,DispatcherType.FORWARD})
public class FilterTest1 implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String username = servletRequest.getParameter("username");
        System.out.println("1");
        if (username.equals("admin")) {
            filterChain.doFilter(servletRequest, servletResponse);
            System.out.println("filter1放行了");
        }else {
            servletResponse.setContentType("text/html;charset=UTF-8");
            System.out.println("filter1没放行");
            servletResponse.getWriter().write("访问失败");
        }
    }
}